﻿using MemberModel;

namespace MemberDal
{
    public class adminDal
    {
        public adminDal(MyDBContent db)
        {
            Db = db;
        }

        public MyDBContent Db { get; }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="zhang">账号</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public T_Admin GetAdmin(string zhang, string pwd)
        {
            try
            {
                T_Admin list = Db.t_Admins.Where(x=>x.A_Zhang == zhang && x.A_Pwd == pwd).FirstOrDefault();
                return list;
            }
            catch (Exception)
            {
                throw;
            }
        }


        /// <summary>
        /// 显示会员登录列表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        public List<T_Admin> GetAdminInfo(string? name,int? age)
        {
            try
            {
                List<T_Admin> list = Db.t_Admins.ToList();
                if (!string.IsNullOrEmpty(name))
                {
                    list = list.Where(x=>x.A_Name.Contains(name)).ToList();
                }
                if(age > 0)
                {
                    list = list.Where(x=>x.A_Age ==age).ToList();
                }
                return list;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="info">实体类</param>
        /// <returns></returns>
        public int PutAdminInfo(T_Admin info)
        {
            try
            {
                Db.t_Admins.Find(info.A_Id); 
                return Db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 反填数据
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public T_Admin Fantian(int aid)
        {
            try
            {
                T_Admin list = Db.t_Admins.Find(aid);
                return list;

            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}